package com.glh.javalogic.chapter4;

import android.util.Log;
import android.view.View;

import com.glh.javalogic.R;
import com.glh.javalogic.chapter4.concept.ArrowLine;
import com.glh.javalogic.chapter4.concept.Circle;
import com.glh.javalogic.chapter4.concept.Line;
import com.glh.javalogic.chapter4.concept.Point;
import com.glh.javalogic.chapter4.concept.ShapeManager;
import com.glh.javalogic.chapter4.detail.Base1;
import com.glh.javalogic.chapter4.detail.Child;
import com.glh.javalogic.chapter4.detail.Child1;
import com.glh.javalogic.chapter4.doubleedged.ChildV1;
import com.glh.javalogic.chapter4.doubleedged.ChildV2;
import com.glh.javalogic.common.BaseActivity;

/**
 * <pre>
 *     author : 高磊华
 *     e-mail : 984992087@qq.com
 *     time   : 2018/06/09
 *     desc   : 第4章 类的继承
 * </pre>
 */


public class chapter_4Activity extends BaseActivity implements View.OnClickListener {

    private static final String TAG = "chapter_4Activity";

    @Override
    protected int getContentResourseId() {
        return R.layout.activity_chapter_4;
    }

    @Override
    protected void init() {
        findViewById(R.id.btn1).setOnClickListener(this);
        findViewById(R.id.btn2).setOnClickListener(this);
        findViewById(R.id.btn3).setOnClickListener(this);
        findViewById(R.id.btn4).setOnClickListener(this);
        findViewById(R.id.btn5).setOnClickListener(this);
        findViewById(R.id.btn6).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn1:
                Point center = new Point(2, 3);
                //创建圆，赋值给circle
                Circle circle = new Circle(center, 2);
                //调用draw方法，会执行Circle的draw方法
                circle.draw();
                //输出圆面积
                System.out.println(circle.area());
                break;
            case R.id.btn2:
                ShapeManager manager = new ShapeManager();
                manager.addShape(new Circle(new Point(4, 4), 3));
                manager.addShape(new Line(new Point(2, 3),
                        new Point(3, 4), "green"));
                manager.addShape(new ArrowLine(new Point(1, 2),
                        new Point(5, 5), "black", false, true));

                manager.draw();
                break;
            case R.id.btn3:
                Child c = new Child();
                c.test();
                break;
            case R.id.btn4:
                Child1 c1 = new Child1();
                Base1 b1 = c1;
                Log.e(TAG, "重名与静态绑定....." + "外部调用: " + b1.s);
                Log.e(TAG, "重名与静态绑定....." + "外部调用: : " + b1.m);
                b1.staticTest();
                Log.e(TAG, "重名与静态绑定....." + "外部调用: " + c1.s);
                Log.e(TAG, "重名与静态绑定....." + "外部调用: : " + c1.m);
                c1.staticTest();
                break;
            case R.id.btn5:
                ChildV1 cv1 = new ChildV1();
                cv1.addAll(new int[]{1, 2, 3});
                Log.e(TAG, "继承是把双刃剑....... " + cv1.getSum());
                break;
            case R.id.btn6:
                ChildV2 cv2 = new ChildV2();
                cv2.addAll(new int[]{1, 2, 3});
                Log.e(TAG, "继承是把双刃剑....... " + cv2.getSum());
                break;
            default:
                break;
        }
    }
}
